<?php
include("include/config.inc.php");
$itemIdVar    = $_REQUEST['itemIdVar'];
$waiterVar    = $_REQUEST['waiterVar'];
$tableVar     = $_REQUEST['tableVar'];
$tablePartVar = $_REQUEST['tablePartVar'];
$quantity     = $_REQUEST['quantity'];
$plusOrMinus  = $_REQUEST['plusOrMinusVar'];
$startTime    = date('H:i');
$selectItem   = "SELECT orderedItems.quantity,ordermaster.orderId,orderedItems.weight
                   FROM orderedItems
                   JOIN ordermaster
                     ON orderedItems.orderId = ordermaster.orderId
                  WHERE ordermaster.waiterId = '$waiterVar'
                    AND ordermaster.tableId = '$tableVar'
                    AND ordermaster.tablePart = '$tablePartVar'
                    AND ordermaster.orderstatus = 'L' 
                    AND orderedItems.itemId = ".$itemIdVar ;
$orderRes    = mysql_query($selectItem);
$orderRow    = mysql_fetch_array($orderRes);
$oldQuantity = $orderRow['quantity'];
if($plusOrMinus == "null" & $orderRow['weight'] == 0)
{
  $orderId = $orderRow['orderId'];
  $itemId  = $itemIdVar;
  $updateQuantity = "UPDATE orderedItems
                        SET quantity = ".$quantity.", orderTime = '".$startTime."' 
                      WHERE orderId = ".$orderId."
                        AND itemId = ".$itemIdVar ;
  $updateQuantityRes = mysql_query($updateQuantity);
}
else 
{
  if($plusOrMinus == 'plus' & $orderRow['weight'] == 0)
  {
    $orderId  = $orderRow['orderId'];
    $itemId   = $itemIdVar;
    $quantity = $quantity + $oldQuantity  ;
    $updateQuantity = "UPDATE orderedItems
                          SET quantity = ".$quantity.", orderTime = '".$startTime."'
                        WHERE orderId = ".$orderId."
                          AND itemId = ".$itemIdVar ;
    $updateQuantityRes = mysql_query($updateQuantity);
  }
  else if($plusOrMinus == 'minus' & $orderRow['weight'] == 0)
  {
    $orderId  = $orderRow['orderId'];
    $itemId   = $itemIdVar;
    $quantity = $oldQuantity - $quantity;
    if($quantity < 0)
    {
      $msg = "you can not enter minus value of quantity";
    }
    else 
    {
      $updateQuantity = "UPDATE orderedItems
                            SET quantity = ".$quantity.", orderTime = '".$startTime."'
                          WHERE orderId =".$orderId."
                            AND itemId = ".$itemIdVar;
      $updateQuantityRes = mysql_query($updateQuantity);
    }
  }
}
?>
<table align="center" cellpadding="6">
 <!-- <tr>
    <td align="right" class="links"> 
      <a href="closeTables.php">Close Table</a>|<a href="checklogin.php">LogIn</a>
    </td>
  </tr> -->
  <tr>
    <td>
      <iframe src="currentTables.php?waiter=<?php echo $waiterVar; ?>&table=<?php echo $tableVar; ?>&orderId=<?php echo $orderId; ?>" width="500" height="350"></iframe>
    </td>
  </tr>
  <tr>
    <td>
      <iframe id="selectedTableIframe" src="selectedTable.php?waiterId=<?php echo $waiterVar; ?>&tableId=<?php echo $tableVar; ?>&tablePart=<?php echo $tablePartVar; ?>" width="500" height ="490"></iframe>
    </td>
  </tr>
</table>
      